package com.wfs.suanfa.leet;

public class DiGui {
    public static void main(String[] args) {
        System.out.println(two(4));
    }
    public static int one(int n){
        if (n==1) return 1;
        if (n==2) return 2;
        return one(n-1)+one(n-2);
    }
    public static int two(int n){
        if (n==1) return 1;
        if (n==2) return 2;
        int rest=0;
        int pre=2;
        int prepre=1;
        //第一次循环 rest=3  prepre=2 pre=3
        //第二次循环 rest=5 prepre=5 pre=5
        for (int i=3;i<=n;i++){
            rest=pre+prepre;
            prepre=pre;
            pre=rest;
        }
        return rest;
    }
}
